package persentation.presentTeacher;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;

import vo.userVO.StudentVO;

import javax.swing.JScrollPane;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;

public class StudentListPanel extends JPanel{
	
	
	private JScrollPane scrollPane;
	
	private JTable table;
	private JButton button;
	
	private MyTabbedPane tabbedPane;
	private ArrayList<StudentVO> studentList;
	
	
	
	public StudentListPanel(ArrayList<StudentVO> studentList){
		
		this.studentList=studentList;
		setSize(800, 600);
		setLayout(null);
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 10, 780, 404);
		this.add(scrollPane);
		
//		button = new JButton("确    定");
//		button.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				
//			
//				
//				
//			}
//		});
//		button.setBounds(217, 462, 99, 33);
//		button.setFont(new Font("微软雅黑", Font.PLAIN, 18));
//		add(button);
		
		table = new JTable();
		table.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		table.setModel(new DefaultTableModel(
				new Object[][] {
						
						{null, null,null,null},
						
						{null, null,null,null},
						
						
					},
					new String[] {
						"学生ID", "学生姓名","院系名称", "年级",
					}
		) {
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			@SuppressWarnings("rawtypes")
			Class[] columnTypes = new Class[] {
				String.class, String.class, String.class, String.class
			};
			@SuppressWarnings({ "unchecked", "rawtypes" })
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
			
			public boolean isCellEditable(int row, int column)
			{
				
				
			return false;
			}
		});
		table.setBounds(119, 424, 262, 143);
		scrollPane.setViewportView(table);
		table.setForeground(new Color(0, 0, 0));
		table.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
	
		table.add(table.getTableHeader());
		table.getTableHeader().setReorderingAllowed(false);
		table.getTableHeader().setResizingAllowed(false);
		fillTable();
		
		
		
		
			
		
		
	}
	
	
	public void fillTable(){
		System.out.println("++++++++++++++++++++++++++++");
		DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
		 tableModel.setRowCount(0);
		 for(StudentVO student:studentList){
			 String[] array=new String [4];
			 array[0]=student.getId();
			 array[1]=student.getName();
			 
			 array[2]=student.getDepartmentId();
			 array[3]=String.valueOf(student.getGrade());
			 System.out.println(student.getId());
			
			 System.out.println("++++++++++++++++++++++++++++");
			 
			 
			
	 		 
			 
			 tableModel.addRow(array);
			 table.invalidate();
			 table.updateUI();
	      }
		
	}

}
